<%@page import="exception.FriendNotFoundException"%>
<%@page import="java.rmi.RemoteException"%>
<%@page import="exception.NotLoggedInException"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.rmi.Naming"%>
<%@page import="clientData.MemberDataInt"%>
<%@page import="java.util.LinkedList"%>
<%@page import="server.ForumHandlerInt"%>
<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>

	<%
		//System.out.println("adding friend");
		String friendUserName = request.getParameter("friend");
		//System.out.println("friend:"+friendUserName);
		//String userName = "nir123";
		String userName=(String) session.getAttribute("userName");
		if(userName==null) userName="";

		//String password = "123";
		String password=(String) session.getAttribute("password");
		if(password==null) password="";
		
		

	%>

	<%@ include file="serverConnection.jsp" %>

	<%
	LinkedList<MemberDataInt> friends = null;
		try{
			forum.addFriend(userName, password, friendUserName);
			friends = forum.getUserFriends(userName, password);
		}
	catch(FriendNotFoundException s){
		   
		   
		   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
			"no such friend");
		
			response.flushBuffer();
			return;
		   
		   
	   }
			catch(NotLoggedInException t)
			{
				response.sendRedirect("loggin.jsp");
				response.flushBuffer();
				return;
			}
				catch(SQLException s){
					   
					   
					   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
						"SQL server is down");
					
						response.flushBuffer();
						return;
					   
					   
				   }
				   catch(RemoteException u){
					   
					   response.sendError(response.SC_INTERNAL_SERVER_ERROR,
						"forum server is down");
					
						response.flushBuffer();
						return;
				   }
	
	
		
	%>
	<select id="friendsList" name="friendsList" size="10" >
		<%
			for(MemberDataInt friend : friends){	
				%><option value="<%= friend.getUserName()%>"><%= friend.getUserName()%></option><%
			}
		%>
	</select>


